<template>
    <div>
        <!-- <div class="seach">
            <span class="span-top">
                <span class="seachCSC">
                   {{$t('pdtnam')}}
                    <el-select v-model="selectParam.productCode" :placeholder="$t('plsset')" size="mini">
                        <el-option :label="'-' + $t('plsset') + '-'" :value="null"></el-option>
                        <el-option v-for="item in typeList" :key="item.productCode" :label="item.productCodeDesc" :value="item.productCode"></el-option>
                    </el-select>
                </span>
                <span class="seachCSC">
                    {{$t('sta')}}
                    <el-select v-model="selectParam.status" :placeholder="$t('plsset')" size="mini">
                        <el-option :label="'-' + $t('plsset') + '-'" :value="null"></el-option>
                        <el-option v-for="item in statusList" :key="item.statusType" :label="item.statusTypeDesc" :value="item.statusType"></el-option>
                    </el-select>
                </span>
            </span>
            <div class="NOUS">
                <el-button type="primary" @click="getProductList" v-preventReClick>{{$t('qury')}}</el-button>
            </div>
        </div> -->
        <el-button type="warning" @click="showAddProduct" v-if="canAddPro" v-preventReClick>{{$t('add')}}</el-button>
        <el-button class="sdkButton" type="warning" v-if="hadSDK" @click="showAddSDK" v-preventReClick>{{$t('addsdk')}}</el-button>
        <!-- 内容区域 -->
        <el-card class="cardBox">
            <el-table border style="width: 100%" row-key="funcId" :data="resultList">
                <el-table-column prop="merProductId" :label="$t('serialnum')" min-width="200">
                </el-table-column>
                <el-table-column prop="productCode" :label="$t('pdtnam')" min-width="200">
                </el-table-column>
                <el-table-column prop="rateValue" :label="$t('rate')" min-width="100">
                </el-table-column>
                <el-table-column prop="rateType" :label="$t('rattyp')" min-width="150">
                </el-table-column>
                <el-table-column prop="status" :label="$t('sta')" min-width="128">
                </el-table-column>
                 <el-table-column prop="sysGmtModified" :label="$t('modtim')" min-width="144">
                </el-table-column>
                <el-table-column prop="takeEffectTime" :label="$t('efftim')" min-width="141">
                </el-table-column>
                <el-table-column prop="loseEfficacyTime" :label="$t('exptim')" min-width="200">
                </el-table-column>
                <el-table-column :label="$t('opratn')" width="200" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="detail(scope.row.merProductId)">{{$t('detls')}}</el-link>
                        <el-link type="primary" @click="showEdit(scope.row)">{{$t('mdfy')}}</el-link>
                        <el-link type="primary" v-if="scope.row.status === $t('effective')" @click="changSign(scope.row, 'CANCEL')">{{$t('rescission')}}</el-link>
                        <el-link type="primary" v-if="scope.row.status === $t('cancelled')" @click="changSign(scope.row, 'SIGN')">{{$t('signing')}}</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="selectParam.pageNum"
                :page-sizes="[10, 15, 20, 30]"
                :page-size="selectParam.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>
        <span v-if="hadSDK">
            <el-card class="cardBox">
                <el-table border style="width: 100%" row-key="funcId" :data="sdkDataTab">
                    <el-table-column prop="appId" label="appID" min-width="95">
                    </el-table-column>
                    <el-table-column prop="platPubKey" :label="$t('platforthepubkey')" min-width="286">
                    </el-table-column>
                    <el-table-column prop="platPrvKey" :label="$t('platfortheprikey')" min-width="254">
                    </el-table-column>
                    <el-table-column prop="merPubKey" :label="$t('merpubkey')" min-width="254">
                    </el-table-column>
                    <el-table-column prop="merPrvKey" :label="$t('merprikey')" min-width="254">
                    </el-table-column>
                    <el-table-column prop="secretKey" :label="$t('secretkeys')" min-width="90">
                    </el-table-column>
                    <el-table-column prop="status" :label="$t('sta')" min-width="90">
                    </el-table-column>
                    <el-table-column prop="signType" :label="$t('signtype')" min-width="110">
                    </el-table-column>
                    <el-table-column :label="$t('opratn')" width="90" fixed="right">
                        <template slot-scope="scope">
                            <el-link type="primary" @click="showEditSdk(scope.row)">{{$t('mdfy')}}</el-link>
                        </template>
                    </el-table-column>
                </el-table>
            </el-card>
        </span>
        <!-- 添加sdk -->
        <el-dialog :title="$t('addsdk')" :visible.sync="sdkDialogVisible" width="30%" @close="sdkDialogVisibleClosed(addSdkForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="addSdkForm" :rules="addSdkRul" :model="addSdkForm" label-width="80px" :hide-required-asterisk="true">
               <el-form-item :label="$t('signtype')" prop="signType">
                    <el-select v-model="addSdkForm.signType" :placeholder="$t('plsset')" class="selctwidth">
                        <el-option label="RSA" value="RSA"></el-option>
                    </el-select>
               </el-form-item>
               <el-form-item label="app ID" prop="appId">
                    <el-input v-model="addSdkForm.appId" placeholder="app ID"></el-input>
               </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="addSdk(addSdkForm)" v-preventReClick>{{$t('cfm')}}</el-button>
                <el-button @click="sdkDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
        <!-- 修改sdk -->
        <el-dialog :title="$t('editsdk')" :visible.sync="esdkDialogVisible" width="30%" @close="esdkDialogVisibleClosed(editSdkForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="editSdkForm" :rules="editSdkRul" :model="editSdkForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('secretkeys')" prop="secretKey">
                    <el-input v-model.trim="editSdkForm.secretKey" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item label="app ID" prop="appId">
                    <el-input v-model="editSdkForm.appId" placeholder="app ID"></el-input>
               </el-form-item>
               <el-form-item :label="$t('sta')" prop="status">
                    <el-select v-model="editSdkForm.status" :placeholder="$t('plsset')" class="selctwidth">
                        <el-option :label="$t('vlid')" value="VALID"></el-option>
                        <el-option :label="$t('invlid')" value="INVALID"></el-option>
                    </el-select>
               </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="editSdk(editSdkForm)" v-preventReClick>{{$t('cfm')}}</el-button>
                <el-button @click="esdkDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
         <!-- 添加弹框 -->
        <el-dialog :title="$t('addmerchantpro')" :visible.sync="addDialogVisible" width="30%" @close="addDialogVisibleClosed(addForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="addForm" :rules="addProductRul" :model="addForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('mertnam')" prop="merName">
                    <el-input :disabled="true" v-model.trim="merInfo.merName" :placeholder="$t('plsipt')" type="merName"></el-input>
                </el-form-item>
                <el-form-item :label="$t('product')" prop="productCode">
                    <el-select v-model="addForm.productCode" :placeholder="$t('plsset')" class="selctwidth">
                        <el-option
                        v-for="(item, i) in typeList"
                        :key="i"
                        :label="item.productCodeDesc"
                        :value="item.productCode">
                        </el-option>
                </el-select>
                </el-form-item>
                <el-form-item :label="$t('rattyp')" prop="rateType">
                    <el-select v-model="addForm.rateType" :placeholder="$t('plsset')" class="selctwidth">
                        <el-option :label="$t('percentage')" value="01"></el-option>
                        <el-option :label="$t('presspen')" value="02"></el-option>
                        <el-option :label="$t('blend')" value="03"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item :label="$t('basicrate')" prop="rateValue" :placeholder="$t('plsset')">
                    <el-input v-model.trim="addForm.rateValue"></el-input>
                </el-form-item>
                <el-form-item :label="$t('addrat')" prop="additionRateValue" :placeholder="$t('plsipt')">
                    <el-input v-model.trim="addForm.additionRateValue"></el-input>
                </el-form-item>
                <el-form-item :label="$t('sta')" prop="status">
                    <el-select v-model="addForm.status" :placeholder="$t('plsset')" class="selctwidth">
                        <el-option
                        v-for="item in statusList"
                        :key="item.statusType"
                        :label="item.statusTypeDesc"
                        :value="item.statusType">
                        </el-option>
                </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="addProduct(addForm)" v-preventReClick>{{$t('cfm')}}</el-button>
                <el-button @click="cancle(addForm)" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
        <!-- 修改 -->
        <el-dialog :title="$t('mdfy')" :visible.sync="editDialogVisible" width="30%" @close="editDialogVisibleClosed(editForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
           <el-form :ref="editForm" :rules="editRul" :model="editForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('rattyp')" prop="rateType">
                    <el-select v-model="editForm.rateType" :placeholder="$t('plsset')" class="selctwidth">
                        <el-option :label="$t('percentage')" value="01"></el-option>
                        <el-option :label="$t('presspen')" value="02"></el-option>
                        <el-option :label="$t('blend')" value="03"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item :label="$t('basicrate')" prop="rateValue" :placeholder="$t('plsset')">
                    <el-input v-model.trim="editForm.rateValue"></el-input>
                </el-form-item>
                <el-form-item :label="$t('addrat')" prop="additionRateValue" :placeholder="$t('plsipt')">
                    <el-input v-model.trim="editForm.additionRateValue"></el-input>
                </el-form-item>
                <el-form-item :label="$t('exptim')" prop="loseEfficacyTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="editForm.loseEfficacyTime" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="editPro(editForm)" v-preventReClick>{{$t('cfm')}}</el-button>
                <el-button @click="editDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
        <!-- 详情弹框 -->
        <el-dialog :title="$t('merchantprodetails')" :visible.sync="detailDialogVisible" width="30%" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :model="addForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('mertnam')" prop="merName">
                    <el-input :disabled="true" v-model.trim="productDetail.merName" type="merName"></el-input>
                </el-form-item>
                <el-form-item :label="$t('mertid')" prop="merId" >
                    <el-input :disabled="true" v-model.trim="productDetail.merId"></el-input>
                </el-form-item>
                <el-form-item :label="$t('protnam')" prop="productCode">
                    <el-input :disabled="true" v-model.trim="productDetail.productCode"></el-input>
                </el-form-item>
                <el-form-item :label="$t('rattyp')" prop="rateType">
                    <el-input :disabled="true" v-model.trim="productDetail.rateType"></el-input>
                </el-form-item>
                <el-form-item :label="$t('basicrate')" prop="rateValue">
                    <el-input :disabled="true" v-model.trim="productDetail.rateValue"></el-input>
                </el-form-item>
                  <el-form-item :label="$t('addrat')" prop="additionRateValue">
                    <el-input :disabled="true" v-model.trim="productDetail.additionRateValue"></el-input>
                </el-form-item>
                <el-form-item :label="$t('sta')" prop="status">
                    <el-input :disabled="true" v-model.trim="productDetail.status"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="detailDialogVisible = false" v-preventReClick>{{$t('return')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {
    getmerprolist,
    getmerprotypelist,
    getmerprolistadd,
    getmerprostslist,
    getmerprocgelist,
    getmerprodetlist,
    getmerprobifdetlist,
    modifymerproduct,
    getmersecuritylist,
    addmersecurity,
    editmersecurity
} from '@/libs/reqlist.js'
export default {
    data() {
        var isNumberVlidator = (rule, value, callback) => {
            var pattern = /^[0]+(.[0-9]{1,3})?$/
            if (!pattern.test(value)) {
                return callback(new Error(this.$t('plsenteradecwithdig')))
            } else {
                callback()
            }
        }
        return {
            isOk: false,
            detailDialogVisible: false,
            rateType: '01',
            merId: '',
             // 总条数
            total: 0,
            // 列表查询条件
            selectParam: {
                productCode: null,
                status: null,
                merId: null,
                pageNum: 1,
                pageSize: 10
            },
            // 返回状态码信息
            resultMsg: '',
            // 接收列表返回结果
            resultList: [],
            // 产品类型列表
            typeList: [],
            // 产品状态列表
            statusList: [],
            // 签约/解约参数
            sign: {
                merProductId: '',
                type: ''
            },
            // 添加弹框回显的数据
            merInfo: {
                merName: ''
            },
            editSdkForm: {
                merId: '',
                secretKey: '',
                status: '',
                appId: ''
            },
            addDialogVisible: false,
            esdkDialogVisible: false,
            // 添加产品Form
            addForm: {
                merId: '',
                productCode: '',
                rateType: '01',
                rateValue: '',
                additionRateValue: '',
                status: 'VALID'
            },
            // 产品详情参数
            productDetailParam: {
                merId: '',
                productId: ''
            },
            // 产品详情
            productDetail: {
                merName: '',
                merId: '',
                productCode: '',
                rateType: '',
                rateValue: '',
                additionRateValue: '',
                status: ''
            },
            // 添加表单验证规则
            addProductRul: {
                rateValue: [
                    { required: true, message: this.$t('ratecanety'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ],
                additionRateValue: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ]
            },
            editDialogVisible: false,
            editForm: {
                additionRateValue: '',
                takeEffectTime: null,
                loseEfficacyTime: null,
                rateType: '',
                rateValue: ''
            },
            editRul: {
                rateValue: [
                    { required: true, message: this.$t('ratecanety'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ],
                additionRateValue: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ]
            },
            merProductId: '',
            getSdkForm: {
                merId: '',
                signType: 'RSA',
                appId: ''
            },
            sdkDataTab: [],
            addSdkForm: {
                merId: '',
                signType: '',
                appId: ''
            },
            sdkDialogVisible: false,
            addSdkRul: {
                signType: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'change' }
                ],
                appId: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ]
            },
            editSdkRul: {
                status: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'change' }
                ],
                secretKey: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                appId: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ]
            },
            hadSDK: false,
            canAddPro: false
        }
    },
    methods: {
        // 查询产品列表
        getProductList() {
            getmerprolist(JSON.stringify(this.selectParam)).then(res => {
                if (res.data.code === '000000') {
                    // 分页
                    this.total = res.data.data.total - 0
                    for (let i = 0; i < res.data.data.list.length; i++) {
                        let list = res.data.data.list[i]
                        // 显示转化
                        if (list.productCode === 'SCAN_PAY_CODE') list.productCode = this.$t('paymentbypaymentcode')
                        if (list.productCode === 'SCAN_REC_CODE') list.productCode = this.$t('paybycollectioncode')
                        if (list.productCode === 'SDK_CONSUME') list.productCode = this.$t('sdkconsump')
                        if (list.productCode === 'PLAT_CONSUME') list.productCode = this.$t('platformcon')
                        if (list.productCode === 'SETTLE_PAY') list.productCode = this.$t('settmoney')
                        if (list.status === 'VALID') list.status = this.$t('effective')
                        if (list.status === 'AUDIT') list.status = this.$t('inaudit')
                        if (list.status === 'CLOSED') list.status = this.$t('cancelled')
                        if (list.rateType === '01') list.rateType = this.$t('percentage')
                        if (list.rateType === '02') list.rateType = this.$t('presspen')
                        if (list.rateType === '03') list.rateType = this.$t('blend')
                    }
                    let idx = res.data.data.list.find(item => {
                        return item.productCode === this.$t('sdkconsump')
                    })
                    if (idx !== undefined && idx.status === this.$t('effective')) this.hadSDK = true
                    if (idx !== undefined && idx.status === this.$t('cancelled')) this.hadSDK = false
                    this.resultList = res.data.data.list
                    this.getProductTypeList()
                }
            })
        },
        getSdkDataList () {
            getmersecuritylist(JSON.stringify(this.getSdkForm)).then(res => {
                if (res.data.code === '000000') {
                    this.sdkDataTab = res.data.data
                }
            })
        },
        // 监听页面展示数据条数变化
        handleSizeChange (newSize) {
            this.selectParam.pageSize = newSize
            this.getProductList()
        },
        // 监听总页数变化
        handleCurrentChange (newNum) {
            this.selectParam.pageNum = newNum
            this.getProductList()
        },
        // 查询产品类型列表
        getProductTypeList() {
            getmerprotypelist().then(res => {
                this.typeList = []
                if (res.data.code === '000000') {
                    for (let i = 0; i < res.data.data.length; i++) {
                        let item = res.data.data[i]
                        let isExist = false
                        if (item.productCode === 'SCAN_PAY_CODE') item.productCodeDesc = this.$t('paymentbypaymentcode')
                        if (item.productCode === 'SCAN_REC_CODE') item.productCodeDesc = this.$t('paybycollectioncode')
                        if (item.productCode === 'SDK_CONSUME') item.productCodeDesc = this.$t('sdkconsump')
                        if (item.productCode === 'PLAT_CONSUME') item.productCodeDesc = this.$t('platformcon')
                        if (item.productCode === 'SETTLE_PAY') item.productCodeDesc = this.$t('settmoney')
                        for (let x = 0; x < this.resultList.length; x++) {
                            let mercy = this.resultList[x]
                            if (mercy.productCode === item.productCodeDesc) {
                                isExist = true
                                break
                            }
                        }
                        if (!isExist) this.typeList.push(item)
                    }
                    if (res.data.data.length !== this.resultList.length) this.canAddPro = true
                    if (res.data.data.length === this.resultList.length) this.canAddPro = false
                }
            })
        },
        // 查询产品状态列表
        getProductStatusList() {
            getmerprostslist().then(res => {
                this.statusList = res.data.data
                this.statusList.forEach((item, i) => {
                    if (item.statusType === 'AUDIT') this.statusList.splice(i, 1)
                    if (item.statusType === 'VALID') item.statusTypeDesc = this.$t('effective')
                    if (item.statusType === 'CLOSED') item.statusTypeDesc = this.$t('cancelled')
                })
            })
        },
        // 签约/解约产品
        changSign(pro, type) {
            this.sign.merProductId = pro.merProductId
            this.sign.type = type
            getmerprocgelist(JSON.stringify(this.sign)).then(res => {
                if (res.data.code === '000000') {
                    // 操作成功，给出弹框提示
                    this.$message({
                        message: this.$t('sucfuloper'),
                        type: 'success'
                    })
                    // 重新加载列表
                    this.getProductList()
                } else {
                    this.resultMsg = res.data.message
                    this.$message.error(this.$t('operfailed'))
                }
            })
        },
        // 查询产品详情
        detail(merProductId) {
            this.productDetailParam.merId = this.merId
            this.productDetailParam.productId = merProductId
            this.showDetail()
            getmerprodetlist(JSON.stringify(this.productDetailParam)).then(res => {
                this.productDetail = res.data.data
                // 显示转化
                if (this.productDetail.productCode === 'SCAN_PAY_CODE') this.productDetail.productCode = this.$t('paymentbypaymentcode')
                if (this.productDetail.productCode === 'SCAN_REC_CODE') this.productDetail.productCode = this.$t('paybycollectioncode')
                if (this.productDetail.status === 'VALID') {
                    this.productDetail.status = this.$t('effective')
                } else {
                    this.productDetail.status = this.$t('cancelled')
                }
                if (this.productDetail.rateType === '01') this.productDetail.rateType = this.$t('percentage')
                if (this.productDetail.rateType === '02') this.productDetail.rateType = this.$t('presspen')
                if (this.productDetail.rateType === '03') this.productDetail.rateType = this.$t('blend')
                this.productDetail.merName = window.sessionStorage.getItem('mername')
                this.productDetail.merId = this.merId
            })
        },
        // 展示添加产品弹框
        showAddProduct () {
            // 调用回显
            this.selectMerInfo()
            // this.getProductTypeList()
            // 打开弹窗
            this.addDialogVisible = true
        },
        showDetail() {
              this.detailDialogVisible = true
        },
        // 弹框取消按钮
        cancle(form) {
            this.addDialogVisible = false
            this.$refs[form].resetFields()
        },
        // 添加框关闭触发
        addDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
        },
        sdkDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
        },
        esdkDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
        },
        // 查询商户名称和账号
        selectMerInfo() {
            getmerprobifdetlist(JSON.stringify(this.selectParam)).then(res => {
                if (res.data.code === '000000') {
                    this.merInfo.merName = res.data.data.merName
                }
            })
        },
        // 添加商户产品
        addProduct(form) {
            this.$refs[form].validate((valid) => {
                if (!valid) {
                    return false
                }
                getmerprolistadd(JSON.stringify(this.addForm)).then(res => {
                    this.addDialogVisibleClosed(form)
                    // 成功
                    if (res.data.code === '000000') {
                        // 操作成功，给出弹框提示
                        this.$message({
                            message: this.$t('funaddsuc'),
                            type: 'success'
                        })
                        this.addDialogVisible = false
                        // 重新刷新商户产品列表
                        this.getProductList()
                    } else {
                        this.resultMsg = res.data.message
                        this.$message.error(this.$t('unfunaddsuc'))
                    }
                })
            })
        },
        showEdit (data) {
            this.editForm.additionRateValue = data.additionRateValue
            this.editForm.takeEffectTime = data.takeEffectTime
            this.editForm.loseEfficacyTime = data.loseEfficacyTime
            this.editForm.rateType = data.rateType
            this.editForm.rateValue = data.rateValue
            this.merProductId = data.merProductId
            this.editDialogVisible = true
        },
        editDialogVisibleClosed (form) {
            this.addDialogVisible = false
            this.$refs[form].resetFields()
        },
        editPro (form) {
            this.$refs[form].validate((valid) => {
                if (!valid) {
                    return false
                }
                if (this.editForm.rateType === this.$t('percentage')) this.editForm.rateType = '01'
                if (this.editForm.rateType === this.$t('presspen')) this.editForm.rateType = '02'
                if (this.editForm.rateType === this.$t('blend')) this.editForm.rateType = '03'
                modifymerproduct(this.merProductId, JSON.stringify(this.editForm)).then(res => {
                    if (res.data.code === '000000') {
                        this.$message({
                            message: this.$t('modfunsuc'),
                            type: 'success'
                        })
                        this.editDialogVisible = false
                        // 重新刷新商户产品列表
                        this.getProductList()
                    }
                })
            })
        },
        showAddSDK () {
            this.addSdkForm.merId = this.merId
            this.sdkDialogVisible = true
        },
        addSdk (form) {
            this.$refs[form].validate((valid) => {
                if (!valid) {
                    return false
                }
                addmersecurity(JSON.stringify(this.addSdkForm)).then(res => {
                    switch (res.data.code) {
                        case '000000':
                            this.$message({
                                message: this.$t('funaddsuc'),
                                type: 'success'
                            })
                            this.sdkDialogVisible = false
                            // 重新刷新商户产品列表
                            this.getSdkDataList()
                            break
                        case '020001':
                            this.$message.error(this.$t('mersdkalrexists'))
                            break
                    }
                })
            })
        },
        showEditSdk (data) {
            this.editSdkForm.merId = this.merId
            this.editSdkForm.secretKey = data.secretKey
            this.editSdkForm.status = data.status
            this.editSdkForm.appId = data.appId
            this.esdkDialogVisible = true
        },
        editSdk (form) {
            this.$refs[form].validate((valid) => {
                if (!valid) {
                    return false
                }
                editmersecurity(JSON.stringify(this.editSdkForm)).then(res => {
                    if (res.data.code === '000000') {
                        this.$message({
                            message: this.$t('modfunsuc'),
                            type: 'success'
                        })
                        this.esdkDialogVisible = false
                        // 重新刷新商户产品列表
                        this.getSdkDataList()
                    }
                })
            })
        }
    },
    async mounted () {
        this.selectParam.merId = window.sessionStorage.getItem('merId')
        this.addForm.merId = window.sessionStorage.getItem('merId')
        this.getSdkForm.merId = window.sessionStorage.getItem('merId')
        this.merId = window.sessionStorage.getItem('merId')
        await this.getProductList()
        this.getSdkDataList()
        this.getProductStatusList()
    },
    destroyed () {
        window.sessionStorage.removeItem('merId')
        window.sessionStorage.removeItem('mername')
    }
}
</script>

<style lang="less" scoped>
@import './productList.less';
</style>
